package com.cetc;

import org.junit.Test;

import java.io.*;

/**
 * @Classname IOFileOutPutInputStreamTest
 * @Description TODO
 * @Date 2022/11/24 15:23
 * @Created by louzhuangxi
 */
public class IOFileOutPutInputStreamTest {
    @Test
    public void test01() {
        File sourceFile = new File("data/1.png");
        File targetFile = new File("data/2.png");
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(sourceFile);
            fos = new FileOutputStream(targetFile);
            byte[] bytes = new byte[1024];
            int len;
            while ((len = fis.read(bytes)) != -1) {
                fos.write(bytes, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
                if (fos != null) {
                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
